Title Banner

Previous Book Contents Book Index Next

Inside Macintosh: QuickDraw GX Graphics /
Chapter 4 - Geometric Operations / Using Geometric Operations


Eliminating Unnecessary Geometric Points

There are many ways in which polygon and path shapes can contain more geometric points than necessary to describe their underlying geometry. Two common examples are

The sample function in Listing 4-3 creates a polygon shape with a single contour that has six geometric points, two of which are unnecessary.

Listing 4-3 Creating a polygon with redundant geometric points

void ReduceUnnecessaryPoints(void)
{
   gxShape  squareShape;

   static long paddedSquareGeometry[] = {1, /* # of contours */
                                         6, /* # of contours */
                                         ff(50), ff(50),
                                         ff(100), ff(50),  
                                         ff(150), ff(50),  
                                         ff(150), ff(150),  
                                         ff(150), ff(150),  
                                         ff(50), ff(150)};


   squareShape = GXNewPolygons((gxPolygons *) 
                               &paddedSquareGeometry);
   GXSetShapeFill(squareShape, gxEvenOddFill);

   GXDrawShape(squareShape);
   GXDisposeShape(squareShape);
}
The resulting polygon shape is shown in Figure 4-22.

Figure 4-22 A polygon shape with unnecessary geometric points

QuickDraw GX provides the GXReduceShape function so you can eliminate unnecessary duplicate and colinear points. The GXReduceShape function takes two parameters: a reference to the shape containing the contour whose unnecessary geometric points you want to eliminate and an index specifying the contour itself. If you supply the value 0 for the second parameter, the GXReduceShape function eliminates unnecessary geometric points from all the contours of a shape.

As an example, adding the function call

GXReduceShape(squareShape, 0);
to the sample function in Listing 4-3 results in the polygon shape shown in Figure 4-23.

Figure 4-23 A polygon shape with the unnecessary geometric points removed

The unnecessary duplicate geometric point and the unnecessary colinear geometric point are gone, but the polygon still appears the same when drawn. Although the resulting geometry could be described by a rectangle shape, the shape in this example remains a polygon shape. The GXReduceShape function does not convert the shape type of the original shape. (However, the GXSimplifyShape function, shown in the next section, does convert shape type, when possible.)

The GXReduceShape function considers two points to be duplicate points if they are within the distance from each other specified by the curve error property of the shape's style object. See Chapter 3, "Geometric Styles," in this book for a discussion of curve error.

For a discussion of geometric points, see Chapter 2, "Geometric Shapes," in this book.

For more information about the GXReduceShape function, see page 4-74.


Previous Book Contents Book Index Next

© Apple Computer, Inc.
7 JUL 1996




Navigation graphic, see text links

Main | Page One | What's New | Apple Computer, Inc. | Find It | Contact Us | Help